/**
 * Created by chenli on 16/6/17.
 */

//头部导航下拉
function  selectModel(obj,classname1,classname2,class3) {
    $(obj).mouseover(function () {
        $(this).addClass(classname1);
        $(this).siblings(class3).addClass(classname2);
    }).mouseleave(function () {
        $(obj).removeClass(classname1);
        $(class3).removeClass(classname2);
    })
}
//logo 下拉
function logoSelect() {
    $(".logo_select span").mousemove(function () {
        $(".logo_select").find("ul").show();
    })
    $(".logo_select li").mouseover(function () {
        $(this).addClass("e").siblings("li").removeClass("e");
    })
    $(".logo_select li").click(function () {
        var texts = $(this).text();
        $(".logo_select span").html(texts+'<i class="icon iconfont xiala">&#xe60a;</i>');
        $(".logo_select").find("ul").hide();
    })
}
//菜单筋斗云效果
function switchs(obj) {
    $(obj).each(function () {
        var ths = $(this);
        var tli = ths.find("li");
        var tle = ths.siblings(".bm_swtich_line");
        var tli_width = $(obj).find("li:first").width();
        tle.width(tli_width);
        tli.click(function () {
            var tw = $(this).width();
            tli.removeClass("e");
            $(this).addClass("e");
            tle.stop(true, true).animate({
                width: tw,
                left: $(this).position().left
            })
        })
    })
}
//热门推荐移上去效果
function shink(obj,shade,bottoms) {
    var mm;
    $(obj).mouseover(function () {
        mm = $(this).find(shade);
        mm.stop(false, false).animate({
            bottom: 0+"px"
        })
    }).mouseleave(function () {
        mm.stop(false, false).animate({
            bottom: -bottoms + "px"
        })
    })
}

//热门/新鲜选项卡切换
function qiehuan(obj,list,classd,divboxs) {
    $(obj).find(list).mouseover(function () {
        $(this).addClass(classd).siblings(list).removeClass(classd);
        var indexs=$(this).index();
        $(divboxs).eq(indexs).show().siblings(divboxs).hide();
    })
}


/* ========================================================================
 * 选项卡切换
 * ======================================================================== */


+function ($) {
    'use strict';
    // TAB CLASS DEFINITION
    // ====================

    var Tab = function (element) {
        // jscs:disable requireDollarBeforejQueryAssignment
        this.element = $(element)
        // jscs:enable requireDollarBeforejQueryAssignment
    }

    Tab.VERSION = '3.3.5'

    Tab.TRANSITION_DURATION = 150

    Tab.prototype.show = function () {
        var $this    = this.element
        var $ul      = $this.closest('ul:not(.dropdown-menu)')
        var selector = $this.data('target')

        if (!selector) {
            selector = $this.attr('href')
            selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
        }

        if ($this.parent('li').hasClass('active')) return

        var $previous = $ul.find('.active:last a')
        var hideEvent = $.Event('hide.bs.tab', {
            relatedTarget: $this[0]
        })
        var showEvent = $.Event('show.bs.tab', {
            relatedTarget: $previous[0]
        })

        $previous.trigger(hideEvent)
        $this.trigger(showEvent)

        if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) return

        var $target = $(selector)

        this.activate($this.closest('li'), $ul)
        this.activate($target, $target.parent(), function () {
            $previous.trigger({
                type: 'hidden.bs.tab',
                relatedTarget: $this[0]
            })
            $this.trigger({
                type: 'shown.bs.tab',
                relatedTarget: $previous[0]
            })
        })
    }

    Tab.prototype.activate = function (element, container, callback) {
        var $active    = container.find('> .active')
        var transition = callback
            && $.support.transition
            && ($active.length && $active.hasClass('fade') || !!container.find('> .fade').length)

        function next() {
            $active
                .removeClass('active')
                .find('> .dropdown-menu > .active')
                .removeClass('active')
                .end()
                .find('[data-toggle="tab"]')
                .attr('aria-expanded', false)

            element
                .addClass('active')
                .find('[data-toggle="tab"]')
                .attr('aria-expanded', true)

            if (transition) {
                element[0].offsetWidth // reflow for transition
                element.addClass('in')
            } else {
                element.removeClass('fade')
            }

            if (element.parent('.dropdown-menu').length) {
                element
                    .closest('li.dropdown')
                    .addClass('active')
                    .end()
                    .find('[data-toggle="tab"]')
                    .attr('aria-expanded', true)
            }

            callback && callback()
        }

        $active.length && transition ?
            $active
                .one('bsTransitionEnd', next)
                .emulateTransitionEnd(Tab.TRANSITION_DURATION) :
            next()

        $active.removeClass('in')
    }


    // TAB PLUGIN DEFINITION
    // =====================

    function Plugin(option) {
        return this.each(function () {
            var $this = $(this)
            var data  = $this.data('bs.tab')

            if (!data) $this.data('bs.tab', (data = new Tab(this)))
            if (typeof option == 'string') data[option]()
        })
    }

    var old = $.fn.tab

    $.fn.tab             = Plugin
    $.fn.tab.Constructor = Tab


    // TAB NO CONFLICT
    // ===============

    $.fn.tab.noConflict = function () {
        $.fn.tab = old
        return this
    }


    // TAB DATA-API
    // ============

    var clickHandler = function (e) {
        e.preventDefault()
        Plugin.call($(this), 'show')
    }

    $(document)
        .on('click.bs.tab.data-api', '[data-toggle="tab"]', clickHandler)
        .on('click.bs.tab.data-api', '[data-toggle="pill"]', clickHandler)

}(jQuery);